{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [
    {
     "ename": "Error",
     "evalue": "Jupyter cannot be started. Error attempting to locate jupyter: ",
     "output_type": "error",
     "traceback": [
      "Error: Jupyter cannot be started. Error attempting to locate jupyter:",
      "at A.startServer (/home/baiyin/.vscode-server/extensions/ms-python.python-2020.2.64397/out/client/extension.js:1:786058)",
      "at async A.ensureServerAndNotebookImpl (/home/baiyin/.vscode-server/extensions/ms-python.python-2020.2.64397/out/client/extension.js:1:785513)"
     ]
    }
   ],
   "source": [
    "import requests"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [
    {
     "ename": "Error",
     "evalue": "Jupyter cannot be started. Error attempting to locate jupyter: ",
     "output_type": "error",
     "traceback": [
      "Error: Jupyter cannot be started. Error attempting to locate jupyter:",
      "at A.startServer (/home/baiyin/.vscode-server/extensions/ms-python.python-2020.2.64397/out/client/extension.js:1:786058)",
      "at async A.ensureServerAndNotebookImpl (/home/baiyin/.vscode-server/extensions/ms-python.python-2020.2.64397/out/client/extension.js:1:785513)"
     ]
    }
   ],
   "source": [
    "from bs4 import BeautifulSoup\n",
    "import pandas as pd\n",
    "import lxml.etree"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "- 使用requests获取网页内容"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [
    {
     "ename": "Error",
     "evalue": "Jupyter cannot be started. Error attempting to locate jupyter: ",
     "output_type": "error",
     "traceback": [
      "Error: Jupyter cannot be started. Error attempting to locate jupyter:",
      "at A.startServer (/home/baiyin/.vscode-server/extensions/ms-python.python-2020.2.64397/out/client/extension.js:1:786058)",
      "at async A.ensureServerAndNotebookImpl (/home/baiyin/.vscode-server/extensions/ms-python.python-2020.2.64397/out/client/extension.js:1:785513)"
     ]
    }
   ],
   "source": [
    "user_agent = 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:50.0) Gecko/20100101 Firefox/50.0'\n",
    "header = {'User-Agent': user_agent}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [
    {
     "ename": "Error",
     "evalue": "Jupyter cannot be started. Error attempting to locate jupyter: ",
     "output_type": "error",
     "traceback": [
      "Error: Jupyter cannot be started. Error attempting to locate jupyter:",
      "at A.startServer (/home/baiyin/.vscode-server/extensions/ms-python.python-2020.2.64397/out/client/extension.js:1:786058)",
      "at async A.ensureServerAndNotebookImpl (/home/baiyin/.vscode-server/extensions/ms-python.python-2020.2.64397/out/client/extension.js:1:785513)"
     ]
    }
   ],
   "source": [
    "url = 'https://movie.douban.com/top250'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [
    {
     "ename": "Error",
     "evalue": "Jupyter cannot be started. Error attempting to locate jupyter: ",
     "output_type": "error",
     "traceback": [
      "Error: Jupyter cannot be started. Error attempting to locate jupyter:",
      "at A.startServer (/home/baiyin/.vscode-server/extensions/ms-python.python-2020.2.64397/out/client/extension.js:1:786058)",
      "at async A.ensureServerAndNotebookImpl (/home/baiyin/.vscode-server/extensions/ms-python.python-2020.2.64397/out/client/extension.js:1:785513)"
     ]
    }
   ],
   "source": [
    "res = requests.get(url, headers=header)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [
    {
     "ename": "Error",
     "evalue": "Jupyter cannot be started. Error attempting to locate jupyter: ",
     "output_type": "error",
     "traceback": [
      "Error: Jupyter cannot be started. Error attempting to locate jupyter:",
      "at A.startServer (/home/baiyin/.vscode-server/extensions/ms-python.python-2020.2.64397/out/client/extension.js:1:786058)",
      "at async A.ensureServerAndNotebookImpl (/home/baiyin/.vscode-server/extensions/ms-python.python-2020.2.64397/out/client/extension.js:1:785513)"
     ]
    }
   ],
   "source": [
    "res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [
    {
     "ename": "Error",
     "evalue": "Jupyter cannot be started. Error attempting to locate jupyter: ",
     "output_type": "error",
     "traceback": [
      "Error: Jupyter cannot be started. Error attempting to locate jupyter:",
      "at A.startServer (/home/baiyin/.vscode-server/extensions/ms-python.python-2020.2.64397/out/client/extension.js:1:786058)",
      "at async A.ensureServerAndNotebookImpl (/home/baiyin/.vscode-server/extensions/ms-python.python-2020.2.64397/out/client/extension.js:1:785513)"
     ]
    }
   ],
   "source": [
    "res.cookies"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [
    {
     "ename": "Error",
     "evalue": "Jupyter cannot be started. Error attempting to locate jupyter: ",
     "output_type": "error",
     "traceback": [
      "Error: Jupyter cannot be started. Error attempting to locate jupyter:",
      "at A.startServer (/home/baiyin/.vscode-server/extensions/ms-python.python-2020.2.64397/out/client/extension.js:1:786058)",
      "at async A.ensureServerAndNotebookImpl (/home/baiyin/.vscode-server/extensions/ms-python.python-2020.2.64397/out/client/extension.js:1:785513)"
     ]
    }
   ],
   "source": [
    "res.headers"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [
    {
     "ename": "Error",
     "evalue": "Jupyter cannot be started. Error attempting to locate jupyter: ",
     "output_type": "error",
     "traceback": [
      "Error: Jupyter cannot be started. Error attempting to locate jupyter:",
      "at A.startServer (/home/baiyin/.vscode-server/extensions/ms-python.python-2020.2.64397/out/client/extension.js:1:786058)",
      "at async A.ensureServerAndNotebookImpl (/home/baiyin/.vscode-server/extensions/ms-python.python-2020.2.64397/out/client/extension.js:1:785513)"
     ]
    }
   ],
   "source": [
    "res.url"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [
    {
     "ename": "Error",
     "evalue": "Jupyter cannot be started. Error attempting to locate jupyter: ",
     "output_type": "error",
     "traceback": [
      "Error: Jupyter cannot be started. Error attempting to locate jupyter:",
      "at A.startServer (/home/baiyin/.vscode-server/extensions/ms-python.python-2020.2.64397/out/client/extension.js:1:786058)",
      "at async A.ensureServerAndNotebookImpl (/home/baiyin/.vscode-server/extensions/ms-python.python-2020.2.64397/out/client/extension.js:1:785513)"
     ]
    }
   ],
   "source": [
    "res.request"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [
    {
     "ename": "Error",
     "evalue": "Jupyter cannot be started. Error attempting to locate jupyter: ",
     "output_type": "error",
     "traceback": [
      "Error: Jupyter cannot be started. Error attempting to locate jupyter:",
      "at A.startServer (/home/baiyin/.vscode-server/extensions/ms-python.python-2020.2.64397/out/client/extension.js:1:786058)",
      "at async A.ensureServerAndNotebookImpl (/home/baiyin/.vscode-server/extensions/ms-python.python-2020.2.64397/out/client/extension.js:1:785513)"
     ]
    }
   ],
   "source": [
    "res.status_code"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [
    {
     "ename": "Error",
     "evalue": "Jupyter cannot be started. Error attempting to locate jupyter: ",
     "output_type": "error",
     "traceback": [
      "Error: Jupyter cannot be started. Error attempting to locate jupyter:",
      "at A.startServer (/home/baiyin/.vscode-server/extensions/ms-python.python-2020.2.64397/out/client/extension.js:1:786058)",
      "at async A.ensureServerAndNotebookImpl (/home/baiyin/.vscode-server/extensions/ms-python.python-2020.2.64397/out/client/extension.js:1:785513)"
     ]
    }
   ],
   "source": [
    "res.text"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [
    {
     "ename": "Error",
     "evalue": "Jupyter cannot be started. Error attempting to locate jupyter: ",
     "output_type": "error",
     "traceback": [
      "Error: Jupyter cannot be started. Error attempting to locate jupyter:",
      "at A.startServer (/home/baiyin/.vscode-server/extensions/ms-python.python-2020.2.64397/out/client/extension.js:1:786058)",
      "at async A.ensureServerAndNotebookImpl (/home/baiyin/.vscode-server/extensions/ms-python.python-2020.2.64397/out/client/extension.js:1:785513)"
     ]
    }
   ],
   "source": [
    "with open('douban_top250_page.html', 'w', encoding='utf8') as f:\n",
    "    f.write(res.text)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "- 使用beautufulsoup解析电影名称和url"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [
    {
     "ename": "Error",
     "evalue": "Jupyter cannot be started. Error attempting to locate jupyter: ",
     "output_type": "error",
     "traceback": [
      "Error: Jupyter cannot be started. Error attempting to locate jupyter:",
      "at A.startServer (/home/baiyin/.vscode-server/extensions/ms-python.python-2020.2.64397/out/client/extension.js:1:786058)",
      "at async A.ensureServerAndNotebookImpl (/home/baiyin/.vscode-server/extensions/ms-python.python-2020.2.64397/out/client/extension.js:1:785513)"
     ]
    }
   ],
   "source": [
    "bs_info = BeautifulSoup(res.text, 'html.parser')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [
    {
     "ename": "Error",
     "evalue": "Jupyter cannot be started. Error attempting to locate jupyter: ",
     "output_type": "error",
     "traceback": [
      "Error: Jupyter cannot be started. Error attempting to locate jupyter:",
      "at A.startServer (/home/baiyin/.vscode-server/extensions/ms-python.python-2020.2.64397/out/client/extension.js:1:786058)",
      "at async A.ensureServerAndNotebookImpl (/home/baiyin/.vscode-server/extensions/ms-python.python-2020.2.64397/out/client/extension.js:1:785513)"
     ]
    }
   ],
   "source": [
    "print(bs_info.prettify())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [
    {
     "ename": "Error",
     "evalue": "Jupyter cannot be started. Error attempting to locate jupyter: ",
     "output_type": "error",
     "traceback": [
      "Error: Jupyter cannot be started. Error attempting to locate jupyter:",
      "at A.startServer (/home/baiyin/.vscode-server/extensions/ms-python.python-2020.2.64397/out/client/extension.js:1:786058)",
      "at async A.ensureServerAndNotebookImpl (/home/baiyin/.vscode-server/extensions/ms-python.python-2020.2.64397/out/client/extension.js:1:785513)"
     ]
    }
   ],
   "source": [
    "bs_info.title, bs_info.title.name, bs_info.title.string, bs_info.title.parent.name, bs_info.title.parent.parent.name"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [
    {
     "ename": "Error",
     "evalue": "Jupyter cannot be started. Error attempting to locate jupyter: ",
     "output_type": "error",
     "traceback": [
      "Error: Jupyter cannot be started. Error attempting to locate jupyter:",
      "at A.startServer (/home/baiyin/.vscode-server/extensions/ms-python.python-2020.2.64397/out/client/extension.js:1:786058)",
      "at async A.ensureServerAndNotebookImpl (/home/baiyin/.vscode-server/extensions/ms-python.python-2020.2.64397/out/client/extension.js:1:785513)"
     ]
    }
   ],
   "source": [
    "bs_info.find_all('a')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [
    {
     "ename": "Error",
     "evalue": "Jupyter cannot be started. Error attempting to locate jupyter: ",
     "output_type": "error",
     "traceback": [
      "Error: Jupyter cannot be started. Error attempting to locate jupyter:",
      "at A.startServer (/home/baiyin/.vscode-server/extensions/ms-python.python-2020.2.64397/out/client/extension.js:1:786058)",
      "at async A.ensureServerAndNotebookImpl (/home/baiyin/.vscode-server/extensions/ms-python.python-2020.2.64397/out/client/extension.js:1:785513)"
     ]
    }
   ],
   "source": [
    "file_tags = bs_info.find_all(name='div', attrs={'class': 'hd'})"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [
    {
     "ename": "Error",
     "evalue": "Jupyter cannot be started. Error attempting to locate jupyter: ",
     "output_type": "error",
     "traceback": [
      "Error: Jupyter cannot be started. Error attempting to locate jupyter:",
      "at A.startServer (/home/baiyin/.vscode-server/extensions/ms-python.python-2020.2.64397/out/client/extension.js:1:786058)",
      "at async A.ensureServerAndNotebookImpl (/home/baiyin/.vscode-server/extensions/ms-python.python-2020.2.64397/out/client/extension.js:1:785513)"
     ]
    }
   ],
   "source": [
    "# 找到top250的第一页的电影详情页链接\n",
    "film_urls = []\n",
    "for film_tag in file_tags:\n",
    "    a_tag = film_tag.find('a',)\n",
    "    film_urls.append(a_tag.get('href'))\n",
    "film_urls"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [
    {
     "ename": "Error",
     "evalue": "Jupyter cannot be started. Error attempting to locate jupyter: ",
     "output_type": "error",
     "traceback": [
      "Error: Jupyter cannot be started. Error attempting to locate jupyter:",
      "at A.startServer (/home/baiyin/.vscode-server/extensions/ms-python.python-2020.2.64397/out/client/extension.js:1:786058)",
      "at async A.ensureServerAndNotebookImpl (/home/baiyin/.vscode-server/extensions/ms-python.python-2020.2.64397/out/client/extension.js:1:785513)"
     ]
    }
   ],
   "source": [
    "# 使用requests库请求每个电影连接\n",
    "film_url = film_urls[0]\n",
    "response = requests.get(film_url, headers=header)\n",
    "selector = lxml.etree.HTML(response.text)\n",
    "film_name = selector.xpath('//*[@id=\"content\"]/h1/span[1]/text()')\n",
    "year = selector.xpath('//*[@id=\"content\"]/h1/span[2]/text()')\n",
    "rank = selector.xpath('//*[@id=\"content\"]/div[1]/span[1]/text()')\n",
    "score = selector.xpath('//*[@id=\"interest_sectl\"]/div[1]/div[2]/strong/text()')\n",
    "score_cnt = selector.xpath('//*[@id=\"interest_sectl\"]/div[1]/div[2]/div/div[2]/a/span/text()')\n",
    "introduction = selector.xpath('//*[@id=\"link-report\"]/span[1]/span/text()')\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [
    {
     "ename": "Error",
     "evalue": "Jupyter cannot be started. Error attempting to locate jupyter: ",
     "output_type": "error",
     "traceback": [
      "Error: Jupyter cannot be started. Error attempting to locate jupyter:",
      "at A.startServer (/home/baiyin/.vscode-server/extensions/ms-python.python-2020.2.64397/out/client/extension.js:1:786058)",
      "at async A.ensureServerAndNotebookImpl (/home/baiyin/.vscode-server/extensions/ms-python.python-2020.2.64397/out/client/extension.js:1:785513)"
     ]
    }
   ],
   "source": [
    "film_name,year,rank,score,score_cnt,introduction"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 猫眼电影"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "安装并使用 requests、bs4 库，爬取猫眼电影（）的前 10 个电影名称、电影类型和上映时间，并以 UTF-8 字符集保存到 csv 格式的文件中。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [
    {
     "ename": "Error",
     "evalue": "Jupyter cannot be started. Error attempting to locate jupyter: ",
     "output_type": "error",
     "traceback": [
      "Error: Jupyter cannot be started. Error attempting to locate jupyter:",
      "at A.startServer (/home/baiyin/.vscode-server/extensions/ms-python.python-2020.2.64397/out/client/extension.js:1:786058)",
      "at async A.ensureServerAndNotebookImpl (/home/baiyin/.vscode-server/extensions/ms-python.python-2020.2.64397/out/client/extension.js:1:785513)"
     ]
    }
   ],
   "source": [
    "user_agent = 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:50.0) Gecko/20100101 Firefox/50.0'\n",
    "header = {'user-agent': user_agent}\n",
    "url = 'https://maoyan.com/board/7'  # 猫眼电影热映口碑榜\n",
    "response = requests.get(url, headers=header)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [
    {
     "ename": "Error",
     "evalue": "Jupyter cannot be started. Error attempting to locate jupyter: ",
     "output_type": "error",
     "traceback": [
      "Error: Jupyter cannot be started. Error attempting to locate jupyter:",
      "at A.startServer (/home/baiyin/.vscode-server/extensions/ms-python.python-2020.2.64397/out/client/extension.js:1:786058)",
      "at async A.ensureServerAndNotebookImpl (/home/baiyin/.vscode-server/extensions/ms-python.python-2020.2.64397/out/client/extension.js:1:785513)"
     ]
    }
   ],
   "source": [
    "response.text"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [
    {
     "ename": "Error",
     "evalue": "Jupyter cannot be started. Error attempting to locate jupyter: ",
     "output_type": "error",
     "traceback": [
      "Error: Jupyter cannot be started. Error attempting to locate jupyter:",
      "at A.startServer (/home/baiyin/.vscode-server/extensions/ms-python.python-2020.2.64397/out/client/extension.js:1:786058)",
      "at async A.ensureServerAndNotebookImpl (/home/baiyin/.vscode-server/extensions/ms-python.python-2020.2.64397/out/client/extension.js:1:785513)"
     ]
    }
   ],
   "source": [
    "with open('maoyan_movie_popular.html', 'w', encoding='utf8') as f:\n",
    "    f.write(response.text)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [
    {
     "ename": "Error",
     "evalue": "Jupyter cannot be started. Error attempting to locate jupyter: ",
     "output_type": "error",
     "traceback": [
      "Error: Jupyter cannot be started. Error attempting to locate jupyter:",
      "at A.startServer (/home/baiyin/.vscode-server/extensions/ms-python.python-2020.2.64397/out/client/extension.js:1:786058)",
      "at async A.ensureServerAndNotebookImpl (/home/baiyin/.vscode-server/extensions/ms-python.python-2020.2.64397/out/client/extension.js:1:785513)"
     ]
    }
   ],
   "source": [
    "bs_info = BeautifulSoup(response.text, 'html.parser')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [
    {
     "ename": "Error",
     "evalue": "Jupyter cannot be started. Error attempting to locate jupyter: ",
     "output_type": "error",
     "traceback": [
      "Error: Jupyter cannot be started. Error attempting to locate jupyter:",
      "at A.startServer (/home/baiyin/.vscode-server/extensions/ms-python.python-2020.2.64397/out/client/extension.js:1:786058)",
      "at async A.ensureServerAndNotebookImpl (/home/baiyin/.vscode-server/extensions/ms-python.python-2020.2.64397/out/client/extension.js:1:785513)"
     ]
    }
   ],
   "source": [
    "film_infos = bs_info.find_all('div', attrs={'class': 'movie-item-info'})"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [
    {
     "ename": "Error",
     "evalue": "Jupyter cannot be started. Error attempting to locate jupyter: ",
     "output_type": "error",
     "traceback": [
      "Error: Jupyter cannot be started. Error attempting to locate jupyter:",
      "at A.startServer (/home/baiyin/.vscode-server/extensions/ms-python.python-2020.2.64397/out/client/extension.js:1:786058)",
      "at async A.ensureServerAndNotebookImpl (/home/baiyin/.vscode-server/extensions/ms-python.python-2020.2.64397/out/client/extension.js:1:785513)"
     ]
    }
   ],
   "source": [
    "film_urls = []\n",
    "for film_info in film_infos:\n",
    "    a_tag = film_info.find('a')\n",
    "    film_url = a_tag.get('href')\n",
    "    film_urls.append(film_url)\n",
    "film_urls"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [
    {
     "ename": "Error",
     "evalue": "Jupyter cannot be started. Error attempting to locate jupyter: ",
     "output_type": "error",
     "traceback": [
      "Error: Jupyter cannot be started. Error attempting to locate jupyter:",
      "at A.startServer (/home/baiyin/.vscode-server/extensions/ms-python.python-2020.2.64397/out/client/extension.js:1:786058)",
      "at async A.ensureServerAndNotebookImpl (/home/baiyin/.vscode-server/extensions/ms-python.python-2020.2.64397/out/client/extension.js:1:785513)"
     ]
    }
   ],
   "source": [
    "film_urls = ['https://maoyan.com'+film_url for film_url in film_urls]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [
    {
     "ename": "Error",
     "evalue": "Jupyter cannot be started. Error attempting to locate jupyter: ",
     "output_type": "error",
     "traceback": [
      "Error: Jupyter cannot be started. Error attempting to locate jupyter:",
      "at A.startServer (/home/baiyin/.vscode-server/extensions/ms-python.python-2020.2.64397/out/client/extension.js:1:786058)",
      "at async A.ensureServerAndNotebookImpl (/home/baiyin/.vscode-server/extensions/ms-python.python-2020.2.64397/out/client/extension.js:1:785513)"
     ]
    }
   ],
   "source": [
    "# for film_url in film_urls:\n",
    "response = requests.get(film_urls[0], headers=header)\n",
    "bs_info = BeautifulSoup(response.text, 'html.parser')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [
    {
     "ename": "Error",
     "evalue": "Jupyter cannot be started. Error attempting to locate jupyter: ",
     "output_type": "error",
     "traceback": [
      "Error: Jupyter cannot be started. Error attempting to locate jupyter:",
      "at A.startServer (/home/baiyin/.vscode-server/extensions/ms-python.python-2020.2.64397/out/client/extension.js:1:786058)",
      "at async A.ensureServerAndNotebookImpl (/home/baiyin/.vscode-server/extensions/ms-python.python-2020.2.64397/out/client/extension.js:1:785513)"
     ]
    }
   ],
   "source": [
    "with open('maoyan_movie_popular_film1.html', 'w', encoding='utf8') as f:\n",
    "    f.write(response.text)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [
    {
     "ename": "Error",
     "evalue": "Jupyter cannot be started. Error attempting to locate jupyter: ",
     "output_type": "error",
     "traceback": [
      "Error: Jupyter cannot be started. Error attempting to locate jupyter:",
      "at A.startServer (/home/baiyin/.vscode-server/extensions/ms-python.python-2020.2.64397/out/client/extension.js:1:786058)",
      "at async A.ensureServerAndNotebookImpl (/home/baiyin/.vscode-server/extensions/ms-python.python-2020.2.64397/out/client/extension.js:1:785513)"
     ]
    }
   ],
   "source": [
    "response.text"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [
    {
     "ename": "Error",
     "evalue": "Jupyter cannot be started. Error attempting to locate jupyter: ",
     "output_type": "error",
     "traceback": [
      "Error: Jupyter cannot be started. Error attempting to locate jupyter:",
      "at A.startServer (/home/baiyin/.vscode-server/extensions/ms-python.python-2020.2.64397/out/client/extension.js:1:786058)",
      "at async A.ensureServerAndNotebookImpl (/home/baiyin/.vscode-server/extensions/ms-python.python-2020.2.64397/out/client/extension.js:1:785513)"
     ]
    }
   ],
   "source": [
    "film_info = bs_info.find('h1', attrs={'class': 'name'})\n",
    "film_info"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [
    {
     "ename": "Error",
     "evalue": "Jupyter cannot be started. Error attempting to locate jupyter: ",
     "output_type": "error",
     "traceback": [
      "Error: Jupyter cannot be started. Error attempting to locate jupyter:",
      "at A.startServer (/home/baiyin/.vscode-server/extensions/ms-python.python-2020.2.64397/out/client/extension.js:1:786058)",
      "at async A.ensureServerAndNotebookImpl (/home/baiyin/.vscode-server/extensions/ms-python.python-2020.2.64397/out/client/extension.js:1:785513)"
     ]
    }
   ],
   "source": [
    "film_info.text"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [
    {
     "ename": "Error",
     "evalue": "Jupyter cannot be started. Error attempting to locate jupyter: ",
     "output_type": "error",
     "traceback": [
      "Error: Jupyter cannot be started. Error attempting to locate jupyter:",
      "at A.startServer (/home/baiyin/.vscode-server/extensions/ms-python.python-2020.2.64397/out/client/extension.js:1:786058)",
      "at async A.ensureServerAndNotebookImpl (/home/baiyin/.vscode-server/extensions/ms-python.python-2020.2.64397/out/client/extension.js:1:785513)"
     ]
    }
   ],
   "source": [
    "li_tag = bs_info.find_all('li', attrs={'class': 'ellipsis'})"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [
    {
     "ename": "Error",
     "evalue": "Jupyter cannot be started. Error attempting to locate jupyter: ",
     "output_type": "error",
     "traceback": [
      "Error: Jupyter cannot be started. Error attempting to locate jupyter:",
      "at A.startServer (/home/baiyin/.vscode-server/extensions/ms-python.python-2020.2.64397/out/client/extension.js:1:786058)",
      "at async A.ensureServerAndNotebookImpl (/home/baiyin/.vscode-server/extensions/ms-python.python-2020.2.64397/out/client/extension.js:1:785513)"
     ]
    }
   ],
   "source": [
    "li_tag"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [
    {
     "ename": "Error",
     "evalue": "Jupyter cannot be started. Error attempting to locate jupyter: ",
     "output_type": "error",
     "traceback": [
      "Error: Jupyter cannot be started. Error attempting to locate jupyter:",
      "at A.startServer (/home/baiyin/.vscode-server/extensions/ms-python.python-2020.2.64397/out/client/extension.js:1:786058)",
      "at async A.ensureServerAndNotebookImpl (/home/baiyin/.vscode-server/extensions/ms-python.python-2020.2.64397/out/client/extension.js:1:785513)"
     ]
    }
   ],
   "source": [
    "film_type = []\n",
    "for a_tag in li_tag[0].find_all('a'):\n",
    "    film_type.append(a_tag.text.strip())\n",
    "film_type"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [
    {
     "ename": "Error",
     "evalue": "Jupyter cannot be started. Error attempting to locate jupyter: ",
     "output_type": "error",
     "traceback": [
      "Error: Jupyter cannot be started. Error attempting to locate jupyter:",
      "at A.startServer (/home/baiyin/.vscode-server/extensions/ms-python.python-2020.2.64397/out/client/extension.js:1:786058)",
      "at async A.ensureServerAndNotebookImpl (/home/baiyin/.vscode-server/extensions/ms-python.python-2020.2.64397/out/client/extension.js:1:785513)"
     ]
    }
   ],
   "source": [
    "release_date = li_tag[2].text\n",
    "release_date"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}